package com.strange.mdl.module.mdl.controller.admin.debatehallcomment;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.strange.mdl.framework.common.pojo.PageParam;
import com.strange.mdl.framework.common.pojo.PageResult;
import com.strange.mdl.framework.common.pojo.CommonResult;
import com.strange.mdl.framework.common.util.object.BeanUtils;
import static com.strange.mdl.framework.common.pojo.CommonResult.success;

import com.strange.mdl.framework.excel.core.util.ExcelUtils;

import com.strange.mdl.framework.apilog.core.annotation.ApiAccessLog;
import static com.strange.mdl.framework.apilog.core.enums.OperateTypeEnum.*;

import com.strange.mdl.module.mdl.controller.admin.debatehallcomment.vo.*;
import com.strange.mdl.module.mdl.dal.dataobject.debatehallcomment.DebatehallCommentDO;
import com.strange.mdl.module.mdl.service.debatehallcomment.DebatehallCommentService;

@Tag(name = "管理后台 - 辨经殿话题评论")
@RestController
@RequestMapping("/mdl/debatehall-comment")
@Validated
public class DebatehallCommentController {

    @Resource
    private DebatehallCommentService debatehallCommentService;

    @PostMapping("/create")
    @Operation(summary = "创建辨经殿话题评论")
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:create')")
    public CommonResult<Long> createDebatehallComment(@Valid @RequestBody DebatehallCommentSaveReqVO createReqVO) {
        return success(debatehallCommentService.createDebatehallComment(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新辨经殿话题评论")
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:update')")
    public CommonResult<Boolean> updateDebatehallComment(@Valid @RequestBody DebatehallCommentSaveReqVO updateReqVO) {
        debatehallCommentService.updateDebatehallComment(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除辨经殿话题评论")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:delete')")
    public CommonResult<Boolean> deleteDebatehallComment(@RequestParam("id") Long id) {
        debatehallCommentService.deleteDebatehallComment(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除辨经殿话题评论")
                @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:delete')")
    public CommonResult<Boolean> deleteDebatehallCommentList(@RequestParam("ids") List<Long> ids) {
        debatehallCommentService.deleteDebatehallCommentListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得辨经殿话题评论")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:query')")
    public CommonResult<DebatehallCommentRespVO> getDebatehallComment(@RequestParam("id") Long id) {
        DebatehallCommentDO debatehallComment = debatehallCommentService.getDebatehallComment(id);
        return success(BeanUtils.toBean(debatehallComment, DebatehallCommentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得辨经殿话题评论分页")
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:query')")
    public CommonResult<PageResult<DebatehallCommentRespVO>> getDebatehallCommentPage(@Valid DebatehallCommentPageReqVO pageReqVO) {
        PageResult<DebatehallCommentDO> pageResult = debatehallCommentService.getDebatehallCommentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DebatehallCommentRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出辨经殿话题评论 Excel")
    @PreAuthorize("@ss.hasPermission('mdl:debatehall-comment:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDebatehallCommentExcel(@Valid DebatehallCommentPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DebatehallCommentDO> list = debatehallCommentService.getDebatehallCommentPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "辨经殿话题评论.xls", "数据", DebatehallCommentRespVO.class,
                        BeanUtils.toBean(list, DebatehallCommentRespVO.class));
    }

}